#pragma once

#include "NFComm/NFPluginModule/NFPlatform.h"
#include "NFComm/NFMessageDefine/NFProtocolDefine.hpp"
#include "NFComm/NFMessageDefine/NFMsgDefine.h"

#include "NFComm/NFPluginModule/NFIKernelModule.h"
#include "NFComm/NFPluginModule/NFINetModule.h"
#include "NFComm/NFPluginModule/NFIElementModule.h"
#include "NFComm/NFPluginModule/NFILogModule.h"
#include "NFComm/NFPluginModule/NFIClassModule.h"
#include "NFComm/NFPluginModule/NFINetClientModule.h"
#include "NFComm/NFPluginModule/NFITimerModule.h"

#include <set>

#define LOGIN_IP    "127.0.0.1"         //"120.77.34.4"
#define LOGIN_PORT  14001

//#define NF_REBOT_TIMER_OPERATOR "timer_operator"

enum NFRebotTimerEnum
{
    NF_REBOT_TIMER_OPERATOR = 1,
};

class NFRebot : public NFIModule
{
public:
    static uint32_t     m_staticLoginGameId;
    static uint32_t     m_staticProxyGameId;
    static uint32_t     m_staticRebotId;
public:
    NFRebot(NFIPluginManager* p, uint32_t RebotId);
    virtual ~NFRebot();
public:
    std::string         m_account;
    std::string         m_password;
    std::string         m_securityCode;
    NFGUID              m_guid;
    bool                m_bStartGame;
public:
    NFMsg::AckServerList m_worldList;
    NFMsg::AckConnectWorldResult m_connectWorldResult;
    NFMsg::AckServerList m_gameList;
public:
    uint32_t            m_gateId;
    uint32_t            m_gameId;
    uint32_t            m_loginServerId;
    uint32_t            m_proxyServerId;
    uint32_t            m_rebotServerId;
public:
    bool                m_isConnectedLogin;
    bool                m_isConnectedProxy;
public:
    NFMsg::GameUserBaseInfo m_userBaseInfo;
public:
    NFMsg::GameTableALlInfo m_tableAllInfo;
    NFMsg::AckGetAllTable m_allTable;
    NFMsg::AckGameTableStartGame m_startGame;
public:
    NFINetClientModule* m_pNetClientModule;
    NFILogModule* m_pLogModule;
    NFITimerModule* m_pTimerModule;
public:
    std::set<NFGUID>    m_fullTable;
public:
    virtual bool Init();
    virtual bool AfterInit();
    virtual bool ReadyExecute();
    virtual bool Execute();

    virtual void OnSocketLoginEvent(const int nSockIndex, const NF_NET_EVENT eEvent, NFINet* pNet);
    virtual void OnSocketProxyEvent(const int nSockIndex, const NF_NET_EVENT eEvent, NFINet* pNet);
public:
    virtual int  OnTimeGameUserOperator(const NFGUID& self, const uint32_t nTimerId, const uint64_t nInterVal, const uint32_t nCallCoun);
    virtual int RebotOperator();
public:
    virtual bool ConnectLogin();
    virtual bool ReqLogin();
    virtual bool ReqWorldList();
    virtual bool ReqSelectWorld();
    virtual bool ConnectProxy();
public:
    virtual bool ReqLoginGame();
    virtual bool ReqGameList();
    virtual bool ReqSelectGame();
    virtual bool ReqAckEnterGame();
    virtual bool ReqCreateTable();
    virtual bool ReqGetAllTable();
    virtual bool ReqGetTableInfo();
    virtual bool ReqJoinTable(uint32_t tableId);
    virtual bool ReqSitDown();
    virtual bool ReqStartReady();
    virtual bool ReqStartGame();
    virtual bool ReqAddScore(uint32_t score);
    virtual bool ReqGiveUp();
    virtual bool ReqCompareCard();
    virtual bool ReqLookCard();
public:
    virtual void OnAckLogin(const int nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
    virtual void OnAckWorldList(const int nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
    virtual void OnAckSelectWorld(const int nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
public:
    virtual void OnAckLoginGame(const int nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
    virtual void OnAckGameList(const int nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
    virtual void OnAckSelectGame(const int nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);

public:
    virtual void OnAckEnterGame(const int nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
    virtual void OnAckCreateTable(const int nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
    virtual void OnAckRequestFailed(const int nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
    virtual void OnAckUserStatus(const int nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
    virtual void OnAckGetAllTable(const int nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
    virtual void OnAckGetTableInfo(const int nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
    virtual void OnAckJoinTable(const int nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
    virtual void OnAckStartGame(const int nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
    virtual void OnAckAddScore(const int nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
    virtual void OnAckGiveUp(const int nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
    virtual void OnAckEndCurrentGame(const int nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
    virtual void OnAckEndCurrentTable(const int nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
    virtual void OnAckAllPlayerStartReady(const int nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
    virtual void OnAckLookCard(const int nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
    virtual void OnAckCompareCard(const int nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
};